<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>if语句案例</title>
	<style type="text/css">
		div{
			background: red;
			width: 200px;
			height: 200px;
		}
	</style>
	<script type="text/javascript">
		window.onload=function(){
			 var btn = document.getElementById('btn');
			 var oDiv = document.getElementById('oDiv');
             function show(){
                 oDiv.style.display='block';
                 btn.value='隐藏';
             }

             function close(){
                 oDiv.style.display='none';
                 btn.value='显示';
             }

             btn.onclick=function(){
                 if (oDiv.style.display=='none') {
                 	show();
                 }else{
                 	close();
                 }
             }


		}
	</script>
</head>
<body>
	<input type="button" id="btn" name="" value="显示">
	<div id="oDiv" style="display: none"></div>
</body>
</html>